import router from './router'
import { getToken } from '@/utils/auth' // get token from cookie
const whiteList = ['/login'] // 排除login 

router.beforeEach(async(to, from, next) => {
  const hasToken = getToken()
  if (hasToken) {
    if (to.path === '/'||to.path=="/login") {
      next()
    }else {
      const userInfo =localStorage.getItem("user")
      if (userInfo) {
        next()
      } 
    }
  } 
  else {
    /* has no token*/
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login?redirect=${to.path}`)
    }
  }
})

